package cn.pconline.autoclub.util.ubb.node;

import cn.pconline.autoclub.util.ubb.EscapeUtils;
import cn.pconline.autoclub.util.ubb.Node;

/**
 *
 * @author xhchen
 */
public class QuoteNodeWap extends AbstractNode {

	public QuoteNodeWap() {}

	private QuoteNodeWap(String name, String attribute) {
		super.name = name;
		super.attribute = attribute;
	}

	@Override
	public StringBuilder getText(java.util.LinkedList<Node> stack) {
		StringBuilder sb = new StringBuilder();
        sb.append("<div class=\"reply\">");

        int pos = text.indexOf("{em9001}");
        int length = text.length();
        if (pos != -1) {
            if (text.indexOf("以下是引用") != -1) {
                sb.append("<div class=\"th\">")
                        .append(text.substring(0, pos))
                        .append("</div><br>")
                        .append(text.substring(pos + 8, length));
            } else {
                sb.append("<div class=\"th\">引用&nbsp;")
                        .append(text.substring(0, pos))
                        .append("</div>")
                        .append(text.substring(pos + 8, length));
            }
        } else {
            sb.append("引用&nbsp;").append(text);
        }
        sb.append("</div>\n");
		return sb;
	}

	@Override
	public void appendText(CharSequence text) {
		EscapeUtils.appendHtml(text, super.text);
	}

	@Override
	public Node copyWithoutText() {
		return new QuoteNodeWap(name, attribute);
	}

	@Override
	public Node build(String name, String attribute) {
		return new QuoteNodeWap(name, attribute);
	}

}
